#include "framework.h"
#include "SysConfigInfo.h"

vector<char> SystemConfigInfo::m_socksValidMethods;
map<string, string> SystemConfigInfo::m_userToPwd;
vector<string> SystemConfigInfo::m_ConnRuleSvr;
vector<string> SystemConfigInfo::m_BindRuleSvr;
vector<string> SystemConfigInfo::m_UPDRuleSvr;
int SystemConfigInfo::m_version;

/**********************************************
* SystemConfigInfo
***********************************************/
bool SystemConfigInfo::IsValidMethod(char method)
{
	if(m_socksValidMethods.end() != find(m_socksValidMethods.begin(), m_socksValidMethods.end(), method))
	{
		return true;
	}

	return false;
}

bool SystemConfigInfo::IsValidUser(string userCode, string password)
{
	if(m_userToPwd.find(userCode) != m_userToPwd.end())
	{
		return true;
	}

	return false;
}

bool SystemConfigInfo::IsPermitedSvr(int type, string rmotInfo, uint16_t port)
{
	//***///string remotInfo = rmotInfo + " : ";
	//***///int index;
	//***///switch(type)
	//***///{
	//***///case CMD_CONNECT:
	//***///	for(index = 0; index < m_ConnRuleSvr.size(); index ++)
	//***///	{
	//***///		/* ☆ regex check ☆ */
	//***///		return true;
	//***///	}
	//***///	break;
	//***///	
	//***///case CMD_BIND:
	//***///	for(index = 0; index < m_BindRuleSvr.size(); index ++)
	//***///	{
	//***///		/* ☆ regex check ☆ */
	//***///		return true;
	//***///	}
	//***///	break;
	//***///case CMD_UDP_ASSOCIATE :
	//***///	for(index = 0; index < m_UPDRuleSvr.size(); index ++)
	//***///	{
	//***///		/* ☆ regex check ☆ */
	//***///		return true;
	//***///	}
	//***///	break;
	//***///}
	//***///
	//***///return false;

	return true;
}

char SystemConfigInfo::getSelectedMethod(char numMethod,char* methods)
{
	//***///for(int index = 0; index < numMethod; index ++)
	//***///{
	//***///	if(IsValidMethod(methods[index]) == true)
	//***///	{
	//***///		return methods[index];
	//***///	}
	//***///}
	//***///
	//***////* not selected */
	//***///cout<<"  "<<endl;
	//***///return 0xff;

	return 0x00;
}

bool SystemConfigInfo::readSysConfigInfo(string path)
{
	/* read */
	m_socksValidMethods.push_back('0');
	m_userToPwd["123456"] = "123456";
	/* "remoteInfo : port" */
	m_ConnRuleSvr.push_back("*.*.*.* : *");
	/* "remoteInfo : port" */
	m_BindRuleSvr.push_back("*.*.*.* : *");
	/* "remoteInfo : port" */
	m_UPDRuleSvr.push_back("*.*.*.* : *");
	/* socks protocol version (05) */
	m_version = 5;

	return true;
}

